<?php


namespace app\store\controller\wxapp;


use app\store\controller\Controller;
use app\common\model\Banner as BannerModel;
use think\Db;

class Banner extends Controller
{
    public function index(){
        $model = new BannerModel();
        $banner = $model->getList();
        return $this->fetch('index', compact('banner'));
    }

    public function add(){
        if (!$this->request->isAjax()) {
            return $this->fetch('add');
        }
        $data = $this->postData('goods')['images'];
        if ($data == ''){
            return $this->renderError('请选择图片');
        }
        $model = new BannerModel();
        if ($model->add($data)){
            return $this->renderSuccess('添加成功', url('wxapp.banner/index'));
        }else{
            return $this->renderError('添加失败');
        }

    }

    public function delete($image_id){
        $model = new BannerModel();
        if ($model->setDelete($image_id)){
            return $this->renderSuccess('删除成功', url('wxapp.banner/index'));
        }else{
            return $this->renderError('删除失败');
        }
    }
}